/**
 * Generate code from /{{projectName}}-core/src/main/java/{{packageName}}/core/{{modules}}/service/{{entities@SQL}}Service.java.hbs
 */
package cn.ibizlab.core.authorization.service;

import java.util.*;

import org.springframework.data.domain.Page;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.extension.service.IService;
import cn.ibizlab.util.security.SpringContextHolder;
import cn.ibizlab.util.domain.ImportResult;
import cn.ibizlab.core.authorization.domain.SysRoleMember;
import cn.ibizlab.core.authorization.filter.SysRoleMemberSearchContext;
import cn.ibizlab.core.ad.domain.SysCommonName;
import cn.ibizlab.core.authorization.domain.SysRole;

/**
 * 系统角色成员服务接口[SysRoleMemberService]
 *
 * @author generator
 */
public interface SysRoleMemberService extends IService<SysRoleMember> {

    /**
     * 获取当前Service
     *
     * @return
     */
    default SysRoleMemberService getSelf() {
        return SpringContextHolder.getBean(this.getClass());
    }

    /**
     * 获取
     * @param et
     * @return
     */
    SysRoleMember get(SysRoleMember et);
    /**
     * 获取
     * @param key
     * @return
     */
    default SysRoleMember get(String key) {
        return getSelf().get(new SysRoleMember().setId(key));
    }
    /**
     * id集合获取
     * @param ids
     * @return
     */
    default List<SysRoleMember> getByIds(Collection<String> ids) {
        List<SysRoleMember> entities =new ArrayList<>();
        ids.forEach(key -> entities.add(new SysRoleMember().setId(key)));
        return getSelf().getByEntities(entities);
    }
    /**
     * 对象集合获取
     * @param entities
     * @return
     */
    List<SysRoleMember> getByEntities(List<SysRoleMember> entities);

    /**
     * 草稿
     * @param et
     * @return
     */
    SysRoleMember getDraft(SysRoleMember et);

    /**
     * checkKey
     * @param et
     * @return
     */
    Integer checkKey(SysRoleMember et);

    /**
     * 创建
     * @param et
     * @return
     */
    boolean create(SysRoleMember et);
    /**
     * 批量创建
     * @param list
     * @return
     */
    boolean createBatch(List<SysRoleMember> list);

    /**
     * 更新
     * @param et
     * @return
     */
    boolean update(SysRoleMember et);
    /**
     * 批量更新
     * @param list
     * @return
     */
    boolean updateBatch(List<SysRoleMember> list);

    /**
     * 保存
     * @param et
     * @return
     */
    @Override
    boolean save(SysRoleMember et);
    /**
     * 批量保存
     * @param list
     * @return
     */
    boolean saveBatch(List<SysRoleMember> list);

    /**
     * 主键删除
     * @param key
     * @return
     */
    default boolean remove(String key) {
        return getSelf().remove(new SysRoleMember().setId(key));
    }
    /**
     * 根据keys批量删除
     * @param keys
     * @return
     */
    default boolean remove(List<String> keys) {
        return removeBatch(keys);
    }
    /**
     * 根据对象删除
     * @param et
     * @return
     */
    boolean remove(SysRoleMember et);

    /**
     * 批量删除
     * @param ids
     * @return
     */
    default boolean removeBatch(Collection<String> ids) {
        List<SysRoleMember> entities =new ArrayList<>();
        ids.forEach(key -> entities.add(new SysRoleMember().setId(key)));
        return getSelf().removeByEntities(entities);
    }

    /**
     * 批量删除对象
     * @param entities
     * @return
     */
    boolean removeByEntities(List<SysRoleMember> entities);

    default ImportResult importData(String config, Boolean ignoreError, List<SysRoleMember> list) {
        ImportResult rt = new ImportResult().setTotal(list.size());
        for(int i=0;i<list.size();i++) {
            SysRoleMember et=list.get(i);
            try {
                this.getSelf().save(et);
                rt.setSuccess(rt.getSuccess()+1);
            }catch (Exception ex){
                rt.addItem(i+1,et.getId(),ex.getMessage());
                if(!ignoreError)
                    break;
            }
        }
        return rt;
    }

    /**
     * ListByRoleIds
     * 
     * @param dto
     * @return
     */
    default List<SysRoleMember> listByRoleIds(SysRoleMember dto) {
        return new ArrayList<>();
    }

    /**
     * Member
     * 根据传入role_id系统角色标识查询人员清单，可选过滤参数有: department_id，organization_id，member_group_id，member_name，member_uid
     * @param dto
     * @return
     */
    default List<SysRoleMember> member(SysRoleMember dto) {
        return new ArrayList<>();
    }

    /**
     * searchDefault
     * 
     * @param context
     * @return
     */
    Page<SysRoleMember> searchDefault(SysRoleMemberSearchContext context);
    /**
     * listDefault
     * 
     * @param context
     * @return
     */
    List<SysRoleMember> listDefault(SysRoleMemberSearchContext context);

    /**
     * searchNav
     * 
     * @param context
     * @return
     */
    Page<SysRoleMember> searchNav(SysRoleMemberSearchContext context);
    /**
     * listNav
     * 
     * @param context
     * @return
     */
    List<SysRoleMember> listNav(SysRoleMemberSearchContext context);

    /**
     * searchRoleByGroupId
     * 
     * @param context
     * @return
     */
    Page<SysRoleMember> searchRoleByGroupId(SysRoleMemberSearchContext context);
    /**
     * listRoleByGroupId
     * 
     * @param context
     * @return
     */
    List<SysRoleMember> listRoleByGroupId(SysRoleMemberSearchContext context);

    /**
     * searchRoleByPersonId
     * 
     * @param context
     * @return
     */
    Page<SysRoleMember> searchRoleByPersonId(SysRoleMemberSearchContext context);
    /**
     * listRoleByPersonId
     * 
     * @param context
     * @return
     */
    List<SysRoleMember> listRoleByPersonId(SysRoleMemberSearchContext context);

    /**
     * searchRolesByUserId
     * 
     * @param context
     * @return
     */
    Page<SysRoleMember> searchRolesByUserId(SysRoleMemberSearchContext context);
    /**
     * listRolesByUserId
     * 
     * @param context
     * @return
     */
    List<SysRoleMember> listRolesByUserId(SysRoleMemberSearchContext context);

    /**
     * searchUsersByRoleId
     * 
     * @param context
     * @return
     */
    Page<SysRoleMember> searchUsersByRoleId(SysRoleMemberSearchContext context);
    /**
     * listUsersByRoleId
     * 
     * @param context
     * @return
     */
    List<SysRoleMember> listUsersByRoleId(SysRoleMemberSearchContext context);

    /**
     * 创建实体对象
     * @return
     */
    default SysRoleMember getEntity() {
        return new SysRoleMember();
    }
    /**
     * 创建搜索对象
     * @return
     */
    default SysRoleMemberSearchContext getSearchContext() {
        return new SysRoleMemberSearchContext();
    }
    /**
     * selectRelByMemberUid
     * @param memberUids
     * @return
     */
    List<SysRoleMember> findByMemberUid(List<String> memberUids);
    default List<SysRoleMember> findByMemberUid(String memberUid) {
        return findByMemberUid(Arrays.asList(memberUid));
    }
    /**
     * removeRelByMemberUid
     * @param memberUid
     * @return
     */
    boolean removeByMemberUid(String memberUid);
    /**
     * resetRelByMemberUid
     * @param memberUid
     * @return
     */
    boolean resetByMemberUid(String memberUid);
    /**
     * saveRelByCommonName
     * @param sysCommonName
     * @param list
     * @return
     */
    boolean saveByCommonName(SysCommonName sysCommonName,List<SysRoleMember> list);
    /**
     * saveRelByMemberUid
     * @param memberUid
     * @param list
     * @return
     */
    default boolean saveByMemberUid(String memberUid,List<SysRoleMember> list) {
        return getSelf().saveByCommonName(new SysCommonName().setId(memberUid),list);
    }

    /**
     * selectRelByRoleId
     * @param roleIds
     * @return
     */
    List<SysRoleMember> findByRoleId(List<String> roleIds);
    default List<SysRoleMember> findByRoleId(String roleId) {
        return findByRoleId(Arrays.asList(roleId));
    }
    /**
     * removeRelByRoleId
     * @param roleId
     * @return
     */
    boolean removeByRoleId(String roleId);
    /**
     * resetRelByRoleId
     * @param roleId
     * @return
     */
    boolean resetByRoleId(String roleId);
    /**
     * saveRelByRole
     * @param sysRole
     * @param list
     * @return
     */
    boolean saveByRole(SysRole sysRole,List<SysRoleMember> list);
    /**
     * saveRelByRoleId
     * @param roleId
     * @param list
     * @return
     */
    default boolean saveByRoleId(String roleId,List<SysRoleMember> list) {
        return getSelf().saveByRole(new SysRole().setId(roleId),list);
    }


    /**
     * 自定义查询SQL
     * @param sql  select * from table where id =#{et.param}
     * @param param 参数列表  param.put("param","1");
     * @return
     */
    List<JSONObject> select(String sql, Map<String,Object> param);

    /**
     * 自定义SQL
     * @param sql  update table  set name ='test' where id =#{et.param}
     * @param param 参数列表  param.put("param","1");
     * @return
     */
    boolean execute(String sql, Map<String,Object> param);

}